package com.itheima.Service.Impl.Impl;

//import com.aliyuncs.utils.StringUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.Mapper.CheckItemMapper;
import com.itheima.Service.Impl.CheckItemService;
import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.pojo.CheckItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.apache.commons.lang.StringUtils;

import java.util.List;

@Service
public class CheckItemServiceImpl implements CheckItemService {

    @Autowired
    private CheckItemMapper checkItemMapper;

    /**
     * 分页查询
     * @param queryPageBean
     * @return
     */
    @Override
    public PageResult pageQuery(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        Page<CheckItem> page = checkItemMapper.pageQuery(queryPageBean);

        return new PageResult(page.getTotal(),page.getResult());
    }

    /**
     * 新增检查项
     * @param checkItem
     */
    @Override
    public void add(CheckItem checkItem) {

        checkItemMapper.add(checkItem);

    }

    /**
     * 修改检查项
     * @param checkItem
     */
    @Override
    public void update(CheckItem checkItem) {
        checkItemMapper.update(checkItem);
    }

    /**
     * 根据项目编码或项目名称查询
     * @param idName
     * @return
     */
    @Override
    public List<CheckItem> searchByIdorName(Long idName) {
        boolean numeric = StringUtils.isNumeric(String.valueOf(idName));
        if(numeric){
            return checkItemMapper.searchById(idName);
        }else {
            return checkItemMapper.searchByName(idName);
        }
    }
}
